< previous page page_145 next page >

Page 145
To specify which button is the default, you need to add another constant to the buttons argument of the MsgBox function. You can choose from four possible default button values, which are identified in the following table:
Default Button
Value
Constant
First
0
vbDefaultButton1
Second
256
vbDefaultButton2
Third
512
vbDefaultButton3
Fourth
768
vbDefaultButton4

A user might choose from seven buttons, with the selection depending on the button set used in the message box. Each of these buttons returns a different value to identify the button to your program (see Table 8.3).
Table 7.3 Return Values Indicate the User's Choice
ButtonValueConstant
OK1vbOK
Cancel2vbCancel
Abort3vbAbort
Retry4vbRetry
Ignore5vbIgnore
Yes6vbYes
No7vbNo

As always, using the constant in your code rather than the actual integer value is preferable. After you know which button the user selected, you can use that information in your program.
Making a Message Box Modal
For completeness, you can apply one final setting to the buttons argument of the MsgBox function. You can choose to have the message box be modal for your application or for the entire system. Remember from earlier chapters that when a modal window is shown, it must be closed before continuing with the program. If you specify that the message box is modal to the system, the user must respond to the message box before he or she can do any further work on the computer at all. The system modal option should be used with extreme care. The default behavior is application modal, which means the users can continue to work in other applications.
To use the default, application modal, you do not have to add anything to the buttons argument, or you can add the vbApplicationModal constant, which has a value of 0. To make the message box system modal, you need to add the constant vbSystemModal, which has a value of 4096, to the buttons argument.

 
< previous page page_145 next page >